package main

import (
	"fmt"
	"math/rand"
	"time"
)

func main() {
	//用for实现游戏
	var computer,player int
	var diannaocount,wanjiacount,pingjucount int
	for {
		fmt.Println("请出拳")
		fmt.Scan(&player)
		rand.Seed(time.Now().UnixNano())
		computer = rand.Intn(3) + 1
		fmt.Println(computer)
		if computer == player {
			fmt.Println("平局")
			pingjucount++
		}else if player==1 && computer==2 || player==2 && computer==3 || player==3 && computer==1 {
			fmt.Println("电脑胜")
			diannaocount++
		}else if player==1 && computer==3 || player==2 && computer==1 || player==3 && computer==2{
			fmt.Println("玩家胜")
			wanjiacount++
		}else {
			fmt.Println("输入错误")
		}
		if player==0{
			break
		}
	}

	fmt.Println("电脑胜",diannaocount,"次;","玩家胜",wanjiacount,"次;","平局",pingjucount,"次;")
	//用switch实现
	var num int
	for  {
		rand.Seed(time.Now().UnixNano()) //电脑产生随机数
		in:=rand.Intn(3)+1 //返回[1.3)的随机整数
		fmt.Println(in)
		fmt.Println("请出拳")
		fmt.Scanf("%d",&num) //
		switch num{
		case 1:
			switch in {
			case 1:
				fmt.Println("平局")
			case 2:
				fmt.Println("电脑胜")
			case 3:
				fmt.Println("玩家胜")
			}
		case 2:
			switch in {
			case 1:
				fmt.Println("玩家胜")
			case 2:
				fmt.Println("平局")
			case 3:
				fmt.Println("电脑胜")
			}
		case 3:
			switch in {
			case 1:
				fmt.Println("电脑胜")
			case 2:
				fmt.Println("玩家胜")
			case 3:
				fmt.Println("平局")
			}
		}
	}

}
